home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 05.zip / BS1 part 5 / IM_Install3.adf / piarc.LZH / bmrd.rexx < prev    next >
OS/2 REXX Batch file  |  1992-08-03  |  7KB  |  273 lines

  1. /*
  2.  * BMRD.rexx
  3.  *
  4.  *  Written by: Pete Patterson & Ben Williams
  5.  * Last Update: January 17, 1992
  6.  *         For: Black Belt Systems image processing series IM, IM F/c, and IP.
  7.  * ---------------------------------------------------------------------------
  8.  *    Revision: 1.01
  9.  */
  10.  
  11. /*
  12.  * open rexxsupport.library -- needed for some functions
  13.  */
  14. if ~show('L',"rexxsupport.library") then do
  15.   if addlib('rexxsupport.library',0,-30,0) then do
  16.       /* everything's ok */
  17.     end;
  18.   else do
  19.     say 'We Have A Library Problem, Unable To Load "rexxsupport.library"';
  20.     say 'Cannot operate BMRD.rexx without this library - sorry!';
  21.     exit 10;
  22.     end;
  23.   end;
  24.  
  25. /*
  26.  * This will automatically direct the script to the proper
  27.  * software, if it is running.
  28.  */
  29. prtnme = 'IP_Port'; /* assume Image Professional */
  30. if show('P','IP_Port') = 0 then do
  31.   if show('P','IM_Port') = 0 then do
  32.     say "Can't find image processor's ARexx port!!!"; /* not running? */
  33.     say "This script requires IP, IM or IM F/c to run!";
  34.     exit(20);
  35.     end;
  36.   else do
  37.     prtnme = 'IM_Port'; /* That's the thing about assumptions... */
  38.     end;                 /* We make em, user's break em.          */
  39.   end;
  40.  
  41.   /*
  42.    * This code attempts to read a file called "picmdpath" from REXX:
  43.    * If it can't find it, the script will assume that the commands
  44.    * associated with this PI Module are in "c:". If the file exists,
  45.    * the script will look in the path that is specified in the file.
  46.    * If you create this file, you MUST put a complete, correct path
  47.    * in it; if the commands are in a sub-directory, you have to put
  48.    * the trailing slash on the path (like, device:dir/).
  49.    * 
  50.    */
  51.   cmdpath = 'c:';
  52.   if open(fhandle,'rexx:picmdpath','read') then  /* open the file */
  53.     do
  54.       cmdpath = readln(fhandle);
  55.       call close(fhandle);  /* close the file    */
  56.     end
  57.  
  58. options;
  59. address;
  60.  
  61.   prevpath = 'ram:'; /* put user in ram to start with... */
  62.  
  63.   if show('C',BMpath) = 1 then do
  64.     prevpath = getclip(BMpath);
  65.     end;
  66.  
  67.   address(prtnme);
  68.   options results;
  69.   'current';
  70.   bufdata = result; /* get name of buffer, if there is one */
  71.   parse var bufdata bname ',' bnum ',' bx ',' by ',' btot ',' bmem ',' bparname ',' bparnum;
  72.   if bname ~= '<none>' then do
  73.     bufname = bname;
  74.     end;
  75.   if (length(bufname) > 3) then do
  76.     epos = pos('.pg',bufname,length(bufname)-3);
  77.     if epos ~= 0 then do
  78.       bufname = left(bufname,epos-1)
  79.       end
  80.     end;
  81.   'filerequest "'||prevpath||'","'||bufname||'",".layer1","Load Board"';
  82.   BMfile = result;
  83.   options;
  84.  
  85.   if BMfile = 'FR_CANCELLED' then do
  86.     address(prtnme);
  87.     'imtofront';
  88.     exit 0;
  89.     end;
  90.  
  91.   BMfile = expandfilename(BMfile);
  92.   thispath = gimmepath(BMfile);
  93.   call setclip(BMpath,thispath);
  94.  
  95.   address command cmdpath||'BMRD c "'||BMfile||'"';
  96.   if rc ~= 0 then do
  97.     address(prtnme);
  98.     'message "Cannot read '||BMfile||'"';
  99.     exit 0; /* this is not a proper BM file */
  100.     end;
  101.  
  102.   call open(fhandle,'ram:IP_BMRD.tmp','read');      /* open the file */
  103.   rstring = readln(fhandle);
  104.   call close(fhandle);                     /* close the file    */
  105.   
  106.   address command 'c:delete >nil: ram:IP_BMRD.tmp';
  107.   
  108.   parse var rstring width '/' height '/' depth
  109.  
  110.   if height < 0 then do
  111.     'message "Bad Height: '||height||'"';
  112.     exit 0;
  113.     end;
  114.  
  115.   if height > 32767 then do
  116.     'message "Bad Height: '||height||'"';
  117.     exit 0;
  118.     end;
  119.  
  120.   if width < 0 then do
  121.     'message "Bad Width: '||width||'"';
  122.     exit 0;
  123.     end;
  124.  
  125.   if width > 32767 then do
  126.     'message "Bad Width: '||width||'"';
  127.     exit 0;
  128.     end;
  129.  
  130.   if depth  < 2 then do
  131.     'message "Bad Depth: '||depth||'"';
  132.     exit 0;
  133.     end;
  134.  
  135.   if depth  > 4 then do
  136.     'message "Bad Depth: '||depth||'"';
  137.     exit 0;
  138.     end;
  139.  
  140. 'tofront';
  141.  
  142.   if depth = 2 then do
  143.       options results;
  144.       'gadgets "Pads","Only","Silk","Layer","Layer","One","Layer","Two"';
  145.       pxsz = result-1;
  146.       options;
  147.       if pxsz < 0 then do
  148.         address;
  149.         exit 0;
  150.         end
  151.     end
  152.   else do
  153.       options results;
  154.       'gadgets "Pads","Only","Silk","Layer","Layer","One","Layer","Two","Layer","Three","Layer","Four"';
  155.       pxsz = result-1;
  156.       options;
  157.       if pxsz < 0 then do
  158.         address;
  159.         exit 0;
  160.         end
  161.     end
  162.  
  163.   address(prtnme);
  164.   
  165.   'imtofront'; /* show user the IM screen */
  166.   /* is there already a primary buffer??? */
  167.   options results;
  168.   'current';
  169.   bufdata = result;
  170.   options;
  171.  
  172.   parse var bufdata bname ',' bnum ',' bx ',' by ',' btot ',' bmem ',' bparname ',' bparnum
  173.   if bname ~= '<none>' then do
  174.     address(prtnme);
  175.   options results;
  176.   'askyn '||'"Replace Primary ['||bname||']" "New As Primary"'
  177.   prefs = result;
  178.   options;
  179.   address;
  180.   if prefs = 0 then do
  181.     address(prtnme);
  182.     'killbuff '||bnum; /* this kills the Primary Buffer */
  183.     address;
  184.     end;
  185.   end;
  186.  
  187.   /* New buffer is created at current resolution */
  188.   address(prtnme);
  189.   'autoredraw 0';
  190.   options results;
  191.   'newbuf '||width||' '||height;
  192.   if rc ~= 0 then do
  193.     "message Can't allocate buffer!";
  194.     'autoredraw 1';
  195.     exit 0
  196.     end
  197.   bnum = result;
  198.   options;
  199.   'newcurrent '||bnum;
  200.   'rename '||bnum||' 'gxname;
  201.   address;
  202.  
  203.   address(prtnme);
  204.   options results;
  205.   'jackin';
  206.   jackadr = result;
  207.   options;
  208.  
  209.   'wbtofront';
  210.   'lockimage '||bnum;
  211.   address command cmdpath||'BMRD d'||jackadr||' "'||BMfile||'" '||pxsz;
  212.   'unlockimage '||bnum;
  213.  
  214.   'autoredraw 1';
  215.   address(prtnme);
  216.   'imtofront';
  217.   'redraw';
  218.   address;
  219.  
  220.   exit 0;
  221.  
  222. /*
  223.  * gimmepath
  224.  *
  225.  * This takes the provided argument and sucks the path out of it, then
  226.  * returns that path to the caller, sans file name.
  227.  */
  228. gimmepath:
  229.   arg fullnamegx;
  230.     tempgx = reverse(fullnamegx);
  231.     lengx = length(fullnamegx);   /* get length of string */
  232.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  233.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  234.     seploc = 0; /* assumes current dir, no path supplied */
  235.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  236.       seploc = (lengx - slashdex)+1;
  237.       end;
  238.     else do
  239.       if colondex ~= 0 then do /* we assume we are on a device */
  240.         seploc = (lengx - colondex)+1;
  241.         end;
  242.       end;
  243.   gxname = substr(fullnamegx,seploc+1); /* if you ever need it */
  244.   gxpath = left(fullnamegx,seploc);
  245.   return(gxpath);
  246.  
  247. /*
  248.  * Since this script can't be expected to know where the CD of the user
  249.  * is when this cmd is invoked, we have to check the path the user
  250.  * provides - if it's not specified right from a root, then we have
  251.  * to make it a complete specification from the root.
  252.  */
  253. expandfilename:
  254.   parse arg jfile;
  255.   if index(jfile,':') = 0 then do
  256.     curdir = pragma(D);
  257.     if right(curdir,1) ~= ':' then do
  258.       if right(curdir,1) ~= '/' then do
  259.         if curdir ~= '' then do
  260.           curdir = curdir || '/';
  261.           end;
  262.         end;
  263.       end;
  264.     jfile = curdir||jfile;
  265.     end;
  266.   return(jfile);
  267.  
  268. rvalue:
  269.   wordnum = c2d(readch(fhandle,1)) * 256;
  270.   wordnum = wordnum + c2d(readch(fhandle,1));
  271.   return wordnum;
  272.  
  273.